public class Item implements Comparable<Item>{

	public String itemID;
	public double price;
	public int quantity;

	private static final int MINIMUM_ITEM_ID = 100;
	private static final int MAXIMUM_ITEM_ID = 999;
	private static final double MINIMUM_PRICE = 0.00;
	private static final double MINIMUM_QUANTITY = 0.00;




	public Item (String id, String price, String quantity){
		try{
			itemID=id;
			double itemPrice=Double.parseDouble(price);
			this.price=itemPrice;

			this.quantity=Integer.parseInt(quantity);		

			init();
		}
		catch (NumberFormatException nfe){
			System.out.println("ItemID: "+itemID+ " (wrong input in price or quantity).");
			itemID="Wrong";
		}

	}	

	void init() {

		try{
			if ( itemID.length() < 0 || Integer.parseInt(itemID) < MINIMUM_ITEM_ID ||
					Integer.parseInt(itemID) > MAXIMUM_ITEM_ID ) {

				System.out.println("Out of range Item ID. ("+itemID+")");
				itemID="Wrong";
			}

			if ( itemID.isEmpty() || itemID.equals("") ) {

				System.out.println("Error in Item List: An Item ID field is empty.");
				itemID="Wrong";
			}
			if ( price <= MINIMUM_PRICE ){

				System.out.println("Item Id: "+itemID+" Error in Item List (Negative price) ");
				itemID="Wrong";
			}
			if ( quantity <= MINIMUM_QUANTITY ){

				System.out.println("Item Id: "+itemID+"Error in Item List (Negative quantity) ");
				itemID="Wrong";
			}

		}
		catch (NumberFormatException nfe){
			System.out.println("Wrong ID input in Item List: "+itemID);
			itemID="Wrong";

		}

	}

	public String getItemID() {
		return itemID;
	}


	public void setItemID(String itemID) {
		this.itemID = itemID;
	}


	public double getPrice() {
		return price;
	}


	public void setPrice(double price) {
		this.price = price;
	}


	public int getQuantity() {
		return quantity;
	}


	public void setQuantity(int quantity) {
		this.quantity = quantity;
	}

	public String toString() {
		return " itemID=" + itemID + ", price=" + price + ", quantity="
				+ quantity ;
	}

	public boolean equals(Object other)
	{
		if(other instanceof Item) {
			Item otherItem = (Item) other;
			return itemID.equals(otherItem.getItemID());
		}
		else {
			return false;
		}
	}

	public int compareTo(Item other){
		return itemID.compareTo(other.getItemID());
	}


}


